package com.lam.common.components.dict.model;

import java.util.List;

import com.lam.common.components.dict.constant.DictConstant;
import com.lam.common.utils.CollectionUtil;
import com.lam.common.utils.StringUtils;
import com.lam.common.utils.sql.SqlUtil;

public class TableDictInfo {
	
	/** 没有条件SQL */
	public static final String NO_CONDITION_SQL = "NO_SQL";
	
	private String tableName;
	private String valueField;
	private String textField;
	private String conditionSql;
	private String exeConditionSql = NO_CONDITION_SQL;
	private List<String> varList;
	
	private long cacheExpire = DictConstant.SYS_DICT_EXPIRE;
	
	public TableDictInfo() {
	}
	
	public TableDictInfo(String tableName, String valueField, String textField) {
		this(tableName, valueField, textField, null);
	}
	
	public TableDictInfo(String tableName, String valueField, String textField, String conditionSql) {
		this.tableName = tableName;
		this.valueField = valueField;
		this.textField = textField;
		this.conditionSql = conditionSql;
		this.varList = SqlUtil.getVarList(conditionSql);
	}
	
	public boolean isWithCondition() {
		return StringUtils.isNotBlank(conditionSql) && !conditionSql.equalsIgnoreCase(NO_CONDITION_SQL) && CollectionUtil.isNotEmpty(varList);
	}
	
	public boolean isAnyBlank() {
		return StringUtils.isAnyBlank(tableName, valueField, textField, exeConditionSql);
	}
	
	public String getTableName() {
		return tableName;
	}
	public void setTableName(String tableName) {
		this.tableName = tableName;
	}
	public String getValueField() {
		return valueField;
	}
	public void setValueField(String valueField) {
		this.valueField = valueField;
	}
	public String getTextField() {
		return textField;
	}
	public void setTextField(String textField) {
		this.textField = textField;
	}
	public String getConditionSql() {
		return conditionSql;
	}
	public void setConditionSql(String conditionSql) {
		this.conditionSql = conditionSql;
	}

	public String getExeConditionSql() {
		return exeConditionSql;
	}

	public void setExeConditionSql(String exeConditionSql) {
		this.exeConditionSql = exeConditionSql;
	}
	
	public TableDictInfo exeConditionSql(String exeConditionSql) {
		if(StringUtils.isBlank(exeConditionSql)) {
			this.exeConditionSql = NO_CONDITION_SQL;
		}else {
			this.exeConditionSql = exeConditionSql;
		}
		return this;
	}

	public List<String> getVarList() {
		return varList;
	}

	public void setVarList(List<String> varList) {
		this.varList = varList;
	}

	public long getCacheExpire() {
		return cacheExpire;
	}

	public void setCacheExpire(long cacheExpire) {
		this.cacheExpire = cacheExpire;
	}
	
	public TableDictInfo cacheExpire(long cacheExpire) {
		this.cacheExpire = cacheExpire;
		return this;
	}

}
